<template>
    <div class="customer">
        <div class="QueryClass">
            <el-input class="QueryInput"
                      placeholder="请输入顾客名称模糊搜索" prefix-icon="el-icon-search" v-model="QueryForm.search">
            </el-input>
            <el-button class="QueryButton" @click="QueryCustomer()">搜 索</el-button>
            <el-button class="QueryButton" @click="ExortCustomer()">导出</el-button>
        </div>
        <div class="tab">
            <!--顾客列表-->
            <el-row>
<!--                <el-col :span="6" v-for="commodity in customerList" :key="commodity.id">-->
                    <div>
                        <el-table
                                :data="customerList"
                                stripe="true"
                                border="true"
                                style="width: 100%">
                            <el-table-column
                                    prop="name"
                                    label="名称">
                            </el-table-column>
                            <el-table-column
                                    prop="sex"
                                    label="性别">
                            </el-table-column>
                            <el-table-column
                                    prop="address"
                                    label="地址信息">
                            </el-table-column>
                        </el-table>
                    </div>
<!--                </el-col>-->
            </el-row>
        </div>

        <!--分页条-->
        <div>
            <el-pagination
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
                    :current-page="totalPage"
                    :page-sizes="[3,5,7,9]"
                    :page-size="pageSize"
                    layout="total, sizes, prev, pager, next, jumper"
                    :total="totalCount">
            </el-pagination>
        </div>

    </div>
</template>
<script>
    export default {
        name: "customer.vue",
        data() {
            return {
                totalPage: 1,
                pageSize: 3,
                pageNum:1,
                totalCount: 0,
                QueryForm: {
                    search: ''
                },
                customerList: []
            }
        },
        methods: {
            handleSizeChange(pageSize){
                this.pageSize = pageSize
                this.QueryCustomer()
            },
            handleCurrentChange(pageNum){
                this.pageNum  = pageNum
                this.QueryCustomer()
            },
            QueryCustomer() {
                this.$http.get('/customer', {
                    params: {
                        pageNum: this.pageNum,
                        pageSize: this.pageSize,
                        search: this.QueryForm.search
                    }
                }).then(res => {
                    this.totalCount = res.data.data.totalCount
                    this.totalPage = res.data.data.totalPage
                    this.pageSize =  res.data.data.pageSize
                    this.customerList = res.data.data.list.slice( (this.pageNum-1)*this.pageSize,this.pageNum*this.pageSize)
                    console.log(res.data.data.list)
                })
            },
            ExortCustomer() {
                this.$http.get('/customer/export', null
                ).then(res => {
                    console.log("导出成功", res.data)
                })
            }
        },

        //ytc:页面加载就调用
        created() {
            this.QueryCustomer();
        },
    }
</script>
<style scoped>
    @import url("Customer.css");
</style>